﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using UsersModule;

//idUtilizator*penalizat*idTipUtilizator*activ*lastName
namespace TestingModule
{
    [TestFixture]
    public class UsersModuleTest
    {
        [Test]
        public void TestAdminWorking()
        {
            string sentString = "1*0*1*1*admin";
            Assert.AreEqual(null, UserFactory.GetUser(sentString, "admin"));            
        }

        [Test]
        public void TestAdminNotWorking()
        {
            string sentString = "1*0*2*1*admin";
            Assert.AreNotEqual(null, UserFactory.GetUser(sentString, "admin"));    
        }

        [Test]
        public void TestStudentUserActive()
        {
            string sentString = "1*0*2*1*admin";
            User user = (User)UserFactory.GetUser(sentString, "admin");
            Assert.AreEqual(true,user.Active);  
        }

        [Test]
        [ExpectedException(typeof(IndexOutOfRangeException))]
        public void TestIncorrectReceivedStringFailure1()
        {
            string sentString = "The lazy fox";
            UserFactory.GetUser(sentString, "test");
        }

        [Test]
        [ExpectedException(typeof(FormatException))]
        public void TestIncorrectReceivedStringFailure2()
        {
            string sentString = "test*th*th*th*th";
            UserFactory.GetUser(sentString, "test");
        }

        [Test]      
        public void TestUserTypeTeacher()
        {
            string sentString = "1*0*2*1*admin"; ;
            User test = (User)UserFactory.GetUser(sentString, "test");
            Assert.AreEqual(UserTypes.TEACHER, test.UserType);  
        }

        [Test]
        public void TestUserTypeStudent()
        {
            string sentString = "1*0*3*1*admin"; ;
            User test = (User)UserFactory.GetUser(sentString, "test");
            Assert.AreEqual(UserTypes.STUDENT, test.UserType);
        }

        [Test]
        public void TestUserTypeExternal()
        {
            string sentString = "1*0*4*1*admin"; ;
            User test = (User)UserFactory.GetUser(sentString, "test");
            Assert.AreEqual(UserTypes.EXTERN, test.UserType);
        }

        [Test]
        [ExpectedException(typeof(InvalidCastException))]
        public void TestUserTypePublisherError()
        {
            string sentString = "1*0*5*1*admin"; ;
            User test = (User)UserFactory.GetUser(sentString, "test");           
        }

        [Test]     
        public void TestUserTypePublisher()
        {
            string sentString = "1*0*5*1*admin"; ;
            Publisher test = (Publisher)UserFactory.GetUser(sentString, "test");
            Assert.AreEqual("admin", test.PublisherName);
        }
    }
}
